package com.example.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.Form.*;
import com.example.demo.entity.DoAlertDO;
import com.example.demo.mapper.DoAlertMapper;
import com.example.demo.service.DoAlertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/DoAlert")
public class DoAlertController {
    @Autowired
    private DoAlertService doAlertService;
    @Autowired
    private DoAlertMapper doAlertMapper;

    //查询全部
    @GetMapping("/findAll")
    public List<DoAlertDO> findAll(){

        return  doAlertService.list();
    }
    //有条件的查询
    @GetMapping("/findByForm")
    public List<DoAlertDO> findByForm(SearchForm searchForm){
        return doAlertService.listByForm(searchForm);
    }
    //添加
    @PostMapping("/save")
    public String save(@RequestBody DoAlertDO doAlertDO){
        boolean save = doAlertService.save(doAlertDO);
        if(!save) return "保存失败";
        else return "保存成功";
    }

    //单删
    @DeleteMapping("/deleteById/{id}")
    public String  deleteById(@PathVariable("id") Long id){
        boolean flag = doAlertService.removeById(id);
        if(!flag) return "删除失败";
        else return "删除成功";
    }

    //修改组团信息
    @PutMapping("/update")
    public String update(@RequestBody DoAlertDO doAlertDO){
        boolean update = doAlertService.updateById(doAlertDO);
        if(!update) return "修改失败";
        else return "修改成功";
    }
    //统计表中每天、每周、每月的警告次数
    @GetMapping("/statisticDay")
    public List<DayForm> statisticDay(){
        return doAlertMapper.statisticByDay();
    }
    //统计表中每天、每周、每月的警告次数
    @GetMapping("/statisticWeek")
    public List<WeekForm> statisticWeek(){
        return doAlertMapper.statisticByWeek();
    }
    //统计表中每天、每周、每月的警告次数
    @GetMapping("/statisticMonth")
    public List<MonthForm> statisticMonth(){
        return doAlertMapper.statisticByMonth();
    }
    //分页查询
    @GetMapping("/pageStatistic")
    public Page<DayForm> pageStatistic(@RequestBody SearchDTO searchDTO){
        Page<DayForm> page = new Page<>(1,5);
        doAlertMapper.GetPageDay(page,searchDTO.getMonitorType(),searchDTO.getTableId(), searchDTO.getCreateTime(), searchDTO.getWorkspaceId());
        return page;
    }
    //分页查询
    @GetMapping("/pageStatistic02")
    public Page<WeekForm> pageStatistic02(@RequestBody SearchDTO searchDTO){
        Page<WeekForm> page = new Page<>(1,5);
        doAlertMapper.GetPageWeek(page,searchDTO.getMonitorType(),searchDTO.getTableId(), searchDTO.getCreateTime(), searchDTO.getWorkspaceId());
        return page;
    }
    @GetMapping("/pageStatistic03")
    public Page<MonthForm> pageStatistic03(@RequestBody SearchDTO searchDTO){
        Page<MonthForm> page = new Page<>(1,5);
        doAlertMapper.GetPageMonth(page,searchDTO.getMonitorType(),searchDTO.getTableId(), searchDTO.getCreateTime(), searchDTO.getWorkspaceId());
        return page;
    }

//    //统计表中每天、每周、每月的警告次数
//    @GetMapping("/statisticDay")
//    public List<DayForm> statisticDay(){
//        switch (type){
//            case "day":
//                //每天的警告次数
//                List<DayForm> dayFormList = doAlertMapper.statisticByDay();
////                for(DayForm f:dayFormList){
////                    System.out.println(f);
////                }
//                break;
//            case "week":
//                //每周的警告次数
//                List<WeekForm> weekFormList = doAlertMapper.statisticByWeek();
//                for(WeekForm f:weekFormList){
//                    System.out.println(f);
//                }
//                break;
//            case "month":
//                //每月的警告次数
//                List<MonthForm> monthFormList = doAlertMapper.statisticByMonth();
//                for(MonthForm f:monthFormList){
//                    System.out.println(f);
//                }
//                break;
//            case "growth":
//                List<WeekGrowth> weekGrowths = doAlertMapper.growthByWeek();
//                for(WeekGrowth weekGrowth : weekGrowths){
//                    System.out.println(weekGrowth);
//                }
//        }
//
//    }

}
